package com.socket;

import com.DynamicDebugExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 大忽悠
 * @create 2023/1/11 21:43
 */
@RestController
@RequestMapping("/dynamicDebug")
public class DynamicDebugController {
    @GetMapping
    public Result dynamicDebug(@RequestParam("clasBytes") MultipartFile multipartFile, HttpServletResponse httpServletResponse) {
        try {
            if(multipartFile.isEmpty()){
                return Result.error("class动态debug测试文件内容为空");
            }
            //将执行过程中产生的日志信息和结果全部写到用户socket中
            DynamicDebugExecutor.setSocketOutPutStream(httpServletResponse.getOutputStream());
            DynamicDebugExecutor.execute(multipartFile.getBytes());
            return null;
        } catch (Exception e) {
            return Result.error(e);
        }
    }
}
